﻿using System.Data.SqlClient;
using System.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class UserSystem_Login : System.Web.UI.Page
{
    SqlConnection conn = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        conn = Database.GetConnection();
        if (conn.State == System.Data.ConnectionState.Closed)
        {
            conn.Open();
        }
       
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string username = txtUsername.Text;
        string password = txtPassword.Text;
        string sql = "select * from Employees where Emp_Username = '" + username + "' and Emp_Password = '" + password + "'";
        SqlCommand comm = new SqlCommand(sql, conn);
        SqlDataAdapter adapter = new SqlDataAdapter(comm);
        DataTable dt = new DataTable();
        adapter.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            Session["Employee"] = dt;
            //DataColumn column = new DataColumn();
            string idroles = dt.Rows[0][6].ToString();

            if (idroles == "1")
            {
                Response.Redirect("~/UserSystem/Manager/Homepage.aspx");
            }
            else if (idroles == "2")
            {
                Response.Redirect("~/UserSystem/Employee/Homepage.aspx");
            }
        }
        else
        {
            lblError.Text = "Error";
        }
    }
}